using System;
using System.Reflection;

namespace PropertyExpression.ReactiveRelation
{
    internal class ExpressionWrapperConverter<TSource, TTarget, TProperty> 
        : IPropertyExpressionProxy<TSource, TProperty>
    {
        private readonly IPropertyExpressionProxy<TTarget, TProperty> propertyExpressionProxy;
        private readonly Func<TSource, TTarget> func;

        public ExpressionWrapperConverter(
            IPropertyExpressionProxy<TTarget, TProperty> propertyExpressionProxy,
            Func<TSource, TTarget> func)
        {
            this.propertyExpressionProxy = propertyExpressionProxy;
            this.func = func;
        }

        public PropertyInfo GetPropertyInfo()
        {
            return propertyExpressionProxy.GetPropertyInfo();
        }

        public TProperty Execute(TSource entity)
        {
            return propertyExpressionProxy.Execute(func(entity));
        }
    }
}